package cn.qyd.atomic;

import sun.misc.Unsafe;

/**
 * @author 邱运铎
 * @date 2024-03-24 21:07
 */
public class UnSafeDemo {
    public static void main(String[] args) {
        //这样直接使用会产生异常，因为在使用unsafe会对当前classLoad进行检查，如果不是BootStrapClassLoad，会抛出SecurityException异常
        Unsafe unsafe = Unsafe.getUnsafe();
        int i = 1;
        boolean b = unsafe.compareAndSwapInt(i, 0, 1, 2);
        System.out.println(b);
        System.out.println(i);
    }
}
